<?php


class UserController extends Controller
{
    public function index()
    {
        $data = DB::table('user')->order('id desc')->select();
        $this->assign('title', '用户列表中心');
        $this->assign('list', $data);
        $this->display('User/index.html');
    }

    public function add()
    {
        $this->assign('title', '填个用户啦~');
        $this->display('User/add.html');
    }

    public function insert()
    {
        if (DB::table('user')->insert() > 0) {
            $this->redirect('恭喜您,新增成功!', URL . 'User/index');
        } else {
            $this->redirect('可惜了,新增失败!');
        }
    }

    public function del()
    {
        if (DB::table('user')->delete($_GET['id'])) {
            $this->redirect('恭喜您,删除成功!', URL . 'User/index');
        } else {
            $this->redirect('可惜了,删除失败!', URL . 'User/index');
        }
    }

    public function edit()
    {
        $data = DB::table('user')->find($_GET['id']);
        $this->assign('title', '改个用户啦~');
        $this->assign('data', $data);
        $this->display('User/edit.html');
    }

    public function update()
    {
        if (DB::table('user')->update()) {
            $this->redirect('恭喜您,改动成功!', URL . 'User/index');
        } else {
            $this->redirect('可惜了,改动失败!');
        }
    }

    public function show()
    {
        $db = DB::table('user');
        var_dump($db->select());
    }
}